import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
        public ListNode deleteDuplicates(ListNode head) {
            if(head==null&&head.next==null) return head;
            ListNode newhaed=new ListNode(0);
            ListNode last=newhaed;
            while(head!=null){
                if(head.next!=null&&head.val==head.next.val) {
                    System.out.println("shanchu"+head.val);
                    head=remove(head,head.val);
                }else{
                    System.out.println("bushanchu"+head.val);
                    last.next=head;
                    last=last.next;
                    head=head.next;
                }

            }
            return newhaed.next;
        }
        public ListNode remove(ListNode head,int k){
            while(head!=null){
                if(head.val==k){
                    System.out.print(k);
                    head=head.next;
                }else{
                    return head;
                }
            }
            return null;
        }

    }



public class Yyy {
    public static void main(String[] args) {
        char ch='A';
         
        Map<Integer,ListNode> map=new HashMap<Integer,ListNode>();
        map.put(1,new ListNode(1));
        map.put(2,new ListNode(2));
        for(ListNode l:map.values()){
            System.out.println(l);
        }
      ListNode head = new ListNode(1);
      head.next = new ListNode(2);
      head.next.next = new ListNode(3);
      head.next.next.next = new ListNode(3);
      head.next.next.next.next = new ListNode(4);
      head.next.next.next.next.next = new ListNode(4);
      head.next.next.next.next.next.next = new ListNode(5);
       ListNode newhead = head.deleteDuplicates(head);
    }
}
